clear 
set more off

/*NOTE: PSID_retrospective_analysis.dta is created in the 
        build/PSID folder. */
        
     use  "$PSID/output/PSID_retrospective_analysis.dta", clear
     local yy "70"
     keep if year==1997
        
* Select sample
     keep if rank_father_around1970_3yr!=. & rank_father_around1970_1yr!=. & rank_father_retro_`yy'!=.
     keep if age>=30 & age<=50 

* LOGS 
     estimates clear
     gen indep=.

   *1. 
     replace indep = log_father_retro_`yy'
     eststo: reg log_child_bin indep [pw=xsection_weight], cluster(father_id)

   *2. 
     replace indep = log_father_around1970_1yr
     eststo: reg log_child_bin indep age agesq [pw=xsection_weight], cluster(father_id)

   *3. 
     replace indep = log_father_around1970_3yrs
     eststo: reg log_child_bin indep age agesq [pw=xsection_weight], cluster(father_id)
                
     label var indep "IGE"

     #delimit ; 
          esttab using "$Mydirectory2/appendix_c/PSID_bias_retrospective_log_1997.tex", replace booktabs nostar label  
          keep(indep) nobase noomit nonote alignment(c c) width(\hsize) se(3) b(3) brackets
          mtitle("Retrospective" "\shortstack{Self-reported, \\ 1 year}"  "\shortstack{Self-reported, \\ 3 years}" )
          stats(N, fmt(%09.0gc) label("Observations")) 
     ;
     #delimit cr

* RANKS
     estimates clear

   *1. 
     replace indep = rank_father_retro_`yy'
     eststo: reg rank_child_bin indep [pw=xsection_weight], cluster(father_id)

   *2. 
     replace indep = rank_father_around1970_1yr
     eststo: reg rank_child_bin indep [pw=xsection_weight], cluster(father_id)

   *3. 
     replace indep = rank_father_around1970_3yr
     eststo: reg rank_child_bin indep age agesq [pw=xsection_weight], cluster(father_id)
                
        
     label var indep "Rank-rank correlation"

     #delimit ; 
        esttab using "$Mydirectory2/appendix_c/PSID_bias_retrospective_rank_1997.tex", replace booktabs nostar label  
        keep(indep) nobase noomit nonote alignment(c c) width(\hsize) se(3) b(3) brackets
        mtitle("Retrospective" "\shortstack{Self-reported, \\ 1 year}"  "\shortstack{Self-reported, \\ 3 years}" )
        stats(N, fmt(%09.0gc) label("Observations")) 
     ;
     #delimit cr